<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
	<title>登录</title>
	<link rel="stylesheet" type="text/css" href="../../css/api.css" />
	<style>
		body,
		html {
			width: 100%;
			height: 100vh;
			background: #ffffff;
		}

		header {
			left: 0;
			top: 0;
			right: 0;
			height: 44px;
			padding: 0 15px;
			text-align: center;
			position: fixed;
			background-color: #ffffff;
			font-size: 16px;
			display: flex;
			align-items: center;
			justify-content: space-between;
			z-index: 1000;
		}

		header img {
			width: 22px;
			height: 22px;
		}

		.content {
			box-sizing: border-box;
			padding-top: 80px;
			position: relative;
			height: 100%;
			flex-direction: column;
			display: flex;
			align-items: center;
			justify-content: space-between;
		}

		.wx {
			flex: auto;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			font-size: 16px;
			color: #000000;
			line-height: 20px;
		}

		.wx img {
			width: 60px;
			height: 60px;
			margin-bottom: 20px;
		}

		footer {
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 12px;
			color: #666666;
			line-height: 12px;
			margin: 30px auto;
		}

		footer span {
			color: #ff3a24;
		}

		.password {
			width: 100%;
			padding: 55px 45px 0;
			box-sizing: border-box;
		}

		.password .tit {
			font-size: 30px;
			color: #000000;
			line-height: 30px;
			margin-bottom: 125px;
		}

		.password .count {
			font-size: 14px;
			color: #999;
			line-height: 14px;
		}

		.password .count span {
			color: #ff3a24;
			margin-left: 10px;
		}

		.password .ipt {
			margin: 0 auto;
			width: 100%;
			margin-top: 50px;
			position: relative;
		}

		.password .ipt img {
			width: 22px;
			height: 22px;
			position: absolute;
			right: 7.5px;
			bottom: 8px;
		}

		.password .ipt .get-code {
			width: 90px;
			height: 25px;
			border-radius: 25px;
			border: 1px solid #ff8657;
			color: #ff8657;
			font-size: 12px;
			line-height: 25px;
			text-align: center;
			position: absolute;
			right: 7.5px;
			bottom: 8px;
		}

		.password .ipt .times {
			width: 100px;
			border: 1px solid #f5f5f5;
			color: #ccc;
			background: #f5f5f5;
		}

		.password .ipt input {
			width: 100%;
			font-size: 18px;
			color: #000;
			font-weight: bold;
			padding: 7.5px 0;
			border-bottom: 1px solid #f5f5f5;
			outline: none;
		}

		input::-webkit-input-placeholder {
			color: #999999;
			font-size: 14px;
			font-weight: 500;
		}

		.password .selec {
			font-size: 14px;
			line-height: 14px;
			margin: 50px 0;
			color: #000000;
			display: flex;
			justify-content: space-between;
			align-items: center;
		}

		.password .btn {
			width: 100%;
			height: 50px;
			line-height: 50px;
			text-align: center;
			border-radius: 100px;
			font-size: 16px;
			margin-top: 50px;
		}

		.password .btns_bg {
			background: #ccc;
			color: #fff;
			font-weight: bold;
			margin-bottom: 20px;
		}

		.password .btns_top {
			background-image: linear-gradient(45deg,
					#ff3a24 0%,
					#ff5340 100%);
			color: #ffffff;
			font-weight: bold;
			margin-bottom: 20px;
		}
	</style>
</head>

<body>
	<header>
		<img src="../../image/icon_return.png" alt="" onclick="back()">
	</header>
	<div class="content">
		<div class="password">
			<div class="ipt">
				<input oninput="changes()" id="device_id" placeholder="请输入账号">
			</div>
			<div class="ipt">
				<input oninput="changes()" id='password' type="password" placeholder="请输入密码">
			</div>
			<div class="btn btns_bg" onclick="confirm_logo()">登录</div>
		</div>
		<div class="wx none" tapmode="active" onclick="wxlogin()">
			<img src="../../image/login_icon_wechat.png" alt="">
			<div>微信登录</div>
		</div>
		<footer class="bottom">
			注册或登录即代表您已同意
			<span onclick="explain()">《<span class="app_name"></span>协议》</span>
		</footer>
	</div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript" src="../../script/zepto.js"></script>
<script type="text/javascript">
	var wx;
	let wx_auto;
	let config_info
	apiready = function () {
		$api.fixStatusBar($api.dom('header'));
		wx = api.require('wx');
		config_info = api.getGlobalData({
			key: 'config_info'
		});
		$api.html($api.dom(".app_name"), config_info.app_name);
		if (api.systemType == "ios") {
			if (config_info.format_type) {
				$api.removeCls($api.dom(".password"), 'none');
				$api.css($api.dom(".wx"), 'display:none;');
			}
		}
		api.addEventListener({
			name: 'keyback'
		}, function (ret, err) {
			var frames = api.frames();
			if (frames.findIndex(item => {
				return item.name == "explain"
			}) != -1) {
				api.closeFrame({
					name: "explain"
				});
			} else {
				api.closeWin({
				});
			}
		});
	}

	function wxlogin() {
		if (api.systemType != "ios") {
				wx.isInstalled(function (ret, err) {
				if (ret.installed) {
					wxAuth();
				} else {
					api.toast({
						msg: '请安装微信客户端后重试',
						duration: 2000,
						location: 'middle'
					});
				}
			});
		} else {
			wxAuth();
		}
	}

	function changes() {
		if ($.trim($api.dom("#device_id").value).length > 0 && $.trim($api.dom("#password").value).length > 0) {
			$api.addCls($api.dom('.btn'), 'btns_top');
		} else {
			$api.removeCls($api.dom('.btn'), 'btns_top');
		}
	}

	function confirm_logo() {
		if ($.trim($api.dom("#device_id").value).length > 0 && $.trim($api.dom("#password").value).length > 0) {
			$api.ajax({
				url: 'api/account/login',
				method: 'POST',
				data: {
					values: {
						relation_id: $.trim($api.dom("#device_id").value),
						password: $.trim($api.dom("#password").value),
					}
				}
			}, function (r) {
				$api.setStorage('token', r.data.token);
				memberInfo();
			});
		}
	}

	function wxAuth() {
		wx.auth(function (ret, err) {
			if (ret.status) {
					$api.ajax({
						url: 'api/account/oauth',
						method: 'POST',
						data: {
							values: {
								device_id: '',
								wx_code: ret.code,
							}
						}
					}, function (r) {
						$api.setStorage('token', r.data.token);
						aJpushIDFun();
						memberInfo();
					});

			} else {
				api.toast({
					msg: '微信登录失败,请重试',
					duration: 2000,
					location: 'middle'
				});
			}
		});
	}


	function memberInfo() {
		$api.ajax({
			url: 'api/member/info',
			method: 'get',
		}, function (ret) {
			api.setGlobalData({
				key: 'member_info',
				value: ret.data.info,
			});
			systemInfo();
		});
	}

	function systemInfo() {
		$api.ajax({
			url: 'api/system/info',
			method: 'get',
		}, function (ret) {
			api.setGlobalData({
				key: 'system_info',
				value: ret.data.info,
			});
			back();
		});
	}

	function explain() {
		api.openFrame({
			reload: true,
			name: 'explain',
			url: '../explain.html',
			bgColor: "rgba(0,0,0,0.2)",
			animation: {
				type: "none",
			},
			pageParam: {
				type: 1
			}
		});
	}

	function back() {
		api.closeWin({});
	}

</script>

</html>
